home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
c
/
indents.zip
/
args.c
next >
Wrap
C/C++ Source or Header
|
1993-05-30
|
15KB
|
542 lines
/**
* Copyright (c) 1985 Sun Microsystems, Inc.
* Copyright (c) 1980 The Regents of the University of California.
* Copyright (c) 1976 Board of Trustees of the University of Illinois.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted provided
* that the above copyright notice and this paragraph are duplicated in all
* such forms and that any documentation, advertising materials, and other
* materials related to such distribution and use acknowledge that the
* software was developed by the University of California, Berkeley, the
* University of Illinois, Urbana, and Sun Microsystems, Inc. The name of
* either University or Sun Microsystems may not be used to endorse or
* promote products derived from this software without specific prior written
* permission. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES
* OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
#include "globals.h"
#ifndef lint
# ifndef ANSIC
static char sccsid[] = "@(#)args.c 6.0 (Berkeley) 92/06/15";
# endif /* ANSIC */
#endif /* not lint */
/* Argument scanning and profile reading code. Default parameters are set
* here as well. */
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#ifdef ANSIC
static void scan_profile(FILE *);
#endif /* ANSIC */
/* Profile types */
#define PRO_SPECIAL 1 /* special case */
#define PRO_BOOL 2 /* Boolean */
#define PRO_INT 3 /* integer */
#define PRO_FONT 4 /* troff font */
/* Profile specials for Booleans. Booleans can be set to USE or IGNORE. USE
* reads the value, IGNORE ignores the value and keeps the default */
#define USE 0 /* turn it off */
/* Profile specials for specials */
#define IGNORE 1 /* ignore it */
#define KEY 4 /* type (keyword) */
char *option_source = "?";
/* N.B.: option names can't start with n */
struct pro {
char *p_name; /* name, e.g. -br, -cli */
int p_type; /* type (int, bool, special) */
int p_default; /* the default value (if int) */
int p_special; /* depends on type */
int *p_obj; /* the associated variable */
} pro[] = {
{
"+", PRO_BOOL, true, USE, &cplus
},
{
"T", PRO_SPECIAL, 0, KEY, 0
},
{
"bacc", PRO_BOOL, false, USE, &blanklines_around_conditional_compilation
},
{
"bad", PRO_BOOL, false, USE, &blanklines_after_declarations
},
{
"badp", PRO_BOOL, false, USE, &blanklines_after_declarations_at_proctop
},
{
"bap", PRO_BOOL, false, USE, &blanklines_after_procs
},
{
"bbb", PRO_BOOL, false, USE, &blanklines_before_blockcomments
},
{
"bc", PRO_BOOL, false, USE, &ps.leave_comma
},
{
"br", PRO_BOOL, true, USE, &btype_2
},
{
"brr", PRO_BOOL, false, USE, &btype_3
},
{
"bs", PRO_BOOL, false, USE, &Bill_Shannon
},
{
"c", PRO_INT, 33, 0, &ps.com_ind
},
{
"cci", PRO_INT, 4, 0, &ps.case_code_indent
},
{
"cd", PRO_INT, 0, 0, &ps.decl_com_ind
},
{
"cdb", PRO_BOOL, false, USE, &comment_delimiter_on_blankline
},
{
"ce", PRO_BOOL, true, USE, &cuddle_else
},
{
"ci", PRO_INT, 0, 0, &continuation_indent
},
{
"cli", PRO_INT, 0, 0, &ps.case_indent
},
{
"cp", PRO_INT, 17, 0, &ps.else_endif_col
},
{
"d", PRO_INT, 0, 0, &ps.unindent_displace
},
{
"di", PRO_INT, 16, 0, &ps.decl_indent
},
{
"dj", PRO_BOOL, false, USE, &ps.ljust_decl
},
{
"eei", PRO_BOOL, false, USE, &extra_expression_indent
},
{
"ei", PRO_BOOL, true, USE, &ps.else_if
},
{
"fb", PRO_FONT, 0, 0, (int *) &bodyf
},
{
"fbc", PRO_FONT, 0, 0, (int *) &blkcomf
},
{
"fbx", PRO_FONT, 0, 0, (int *) &boxcomf
},
{
"fc", PRO_FONT, 0, 0, (int *) &scomf
},
{
"fc1", PRO_BOOL, false, USE, &format_col1_comments
},
{
"fk", PRO_FONT, 0, 0, (int *) &keywordf
},
{
"fs", PRO_FONT, 0, 0, (int *) &stringf
},
{
"i", PRO_INT, 4, 0, &ps.ind_size
},
{
"ip", PRO_BOOL, true, USE, &ps.indent_parameters
},
{
"l", PRO_INT, 78, 0, &max_col
},
{
"lc", PRO_INT, 0, 0, &block_comment_max_col
},
{
"ldefs", PRO_BOOL, false, USE, &list_defines
},
{
"lp", PRO_BOOL, true, USE, &lineup_to_parens
},
{
"pcs", PRO_BOOL, false, USE, &proc_calls_space
},
{
"pro", PRO_BOOL, true, USE, &useProfile
},
{
"prs", PRO_BOOL, false, USE, &parens_space
},
{
"ps", PRO_BOOL, false, USE, &pointer_as_binop
},
{
"psl", PRO_BOOL, false, USE, &procnames_start_line
},
{
"sc", PRO_BOOL, true, USE, &star_comment_cont
},
{
"sob", PRO_BOOL, false, USE, &swallow_optional_blanklines
},
{
"st", PRO_BOOL, false, USE, &useStdio
},
{
"tabs", PRO_INT, 8, 0, &tabsize
},
{
"tabu", PRO_BOOL, false, 0, &usetabs
},
{
"troff", PRO_BOOL, false, USE, &troff
},
{
"v", PRO_BOOL, false, USE, &verbose
},
{
0, 0, 0, 0, 0
},
/* whew! */
};
/**
* NAME: void set_profile(void)
*
* FUNCTION: set_profile reads $HOME/indent.pro and ./indent.pro and handles
* arguments given in these files.
*
* ALGORITHM:
*
* PARAMETERS: Reads the environment.
*
* RETURNS:
*
* GLOBALS READ:
*
* GLOBALS CHANGED:
*
* CALLED BY:
*
* HISTORY: Peter Hadfield 09-03-93 Removed the '.' (UNIX hidden file marker)
* from indent.pro to allow the same code to be used for DOS and UNIX.
*
* Added display of profile file path for verbose option.
* Fixed problem with (null) being written into fname if getenv() returns NULL.
*
* Added reading of a profile file with the same path and name as the binary
* (but with a .pro extension).*/
#ifdef ANSIC
void set_profile(char *bin_name)
#else /* ANSIC */
set_profile(bin_name)
char *bin_name;
#endif /* ANSIC */
{
FILE *stream;
char fname[BUFSIZ] = "";
char *env_ptr = NULL;
static char prof[] = "indent.pro"; /* this is no longer a UNIX
* hidden file so the DOS port
* can use the same code */
strcpy(fname, bin_name);
if (fname[strlen(fname) - 4] == '.') /* assume its a DOS file name */
(fname[strlen(fname) - 4] = '\0'); /* remove the extension */
strcat(fname, ".pro");
if ((stream = fopen(option_source = fname, "r")) != NULL) {
if ((verbose) || (show_options))
fprintf(stderr, "Reading profile file: %s", fname);
scan_profile(stream);
(void) fclose(stream);
}
env_ptr = getenv("HOME");
if (env_ptr != NULL) {
sprintf(fname, "%s/%s", env_ptr, prof);
if ((stream = fopen(option_source = fname, "r")) != NULL) {
if ((verbose) || (show_options))
fprintf(stderr, "\nReading profile file: %s", fname);
scan_profile(stream);
(void) fclose(stream);
}
}
sprintf(fname, "%s", prof);
if ((stream = fopen(option_source = fname, "r")) != NULL) {
if ((verbose) || (show_options))
fprintf(stderr, "Reading profile file: %s", fname);
scan_profile(stream);
(void) fclose(stream);
}
option_source